package com.example.xungeng2.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.xungeng2.pojo.TaskPoint;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface TaskPointMapper extends BaseMapper<TaskPoint> {
    @Select("select * from task_point WHERE task_id=#{userId} and sign=0")
    TaskPoint findPointIds(Integer userId);

    @Select("select task_state from user_task where task_id=#{taskId} and user_id=#{userId} and sign=0")
    int selectRWPointState(Integer userId, Integer taskId);

    @Update("update user_task set task_state=1,finish_time=#{date} where task_id=#{taskId} and user_id=#{userId}")
    void finishPoint(int taskId, int userId, String format);


    @Select("select work_id from worker where work_id=#{userId}")
    int selectNowUserRWId(int userId);

    @Update("update worker set not_num=not_num-1 where work_id=#{rwId}")
    void updateNotNumByRWId(int rwId);

    @Select("select task_state from user_task where user_id=#{userId} and task_id=#{taskId} and sign=0")
    Integer selectUserPoint(int userId, int taskId);

    @Insert("insert into user_task (task_id,user_id,sign) values(null,#{user},0)")
    void allotPoint(int user, int point);

    @Update("update user_task set task_state=0,create_time=#{date} where task_id=#{taskId}")
    void changePointState(int taskId, String date);
}
